home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / jikes.lha / jikes-1.11 / src / control.h < prev    next >
C/C++ Source or Header  |  2000-01-06  |  17KB  |  604 lines

  1. // $Id: control.h,v 1.24 2000/01/06 08:24:30 lord Exp $
  2. //
  3. // This software is subject to the terms of the IBM Jikes Compiler
  4. // License Agreement available at the following URL:
  5. // http://www.ibm.com/research/jikes.
  6. // Copyright (C) 1996, 1998, International Business Machines Corporation
  7. // and others.  All Rights Reserved.
  8. // You must accept the terms of that agreement to use this software.
  9. //
  10. #ifndef control_INCLUDED
  11. #define control_INCLUDED
  12.  
  13. #include "config.h"
  14. #include <iostream.h>
  15. #include <stdio.h>
  16. #include "option.h"
  17. #include "symbol.h"
  18. #include "tuple.h"
  19. #include "set.h"
  20.  
  21. class StoragePool;
  22. class Scanner;
  23. class Parser;
  24. class Semantic;
  25. class LexStream;
  26. class AstPackageDeclaration;
  27.  
  28. class Control : public StringConstant
  29. {
  30. public:
  31.     int return_code;
  32.     Option &option;
  33.     SymbolTable classpath_table,
  34.                 external_table;
  35.  
  36.     PackageSymbol *system_package,
  37.                   *java_util_package,
  38.                   *unnamed_package;
  39.     int dot_classpath_index;
  40.     Tuple<PathSymbol *> classpath;
  41.     Tuple<wchar_t *> bad_zip_filenames,
  42.                      bad_input_filenames,
  43.                      unreadable_input_filenames;
  44.  
  45.     SystemTable *system_table;
  46.     Tuple<DirectorySymbol *> system_directories;
  47.  
  48.     Semantic *system_semantic;
  49.     Tuple<Semantic *> semantic;
  50.     Tuple<TypeSymbol *> needs_body_work,
  51.                         type_trash_bin;
  52.  
  53.     NameSymbolMap unnamed_package_types;
  54.  
  55.     SymbolSet input_java_file_set,
  56.               input_class_file_set,
  57.               expired_file_set,
  58.               recompilation_file_set;
  59.  
  60.     Parser *parser;
  61.     Scanner *scanner;
  62.  
  63.     //
  64.     //
  65.     //
  66.     LiteralLookupTable string_table,
  67.                        int_table,
  68.                        long_table,
  69.                        char_table,
  70.                        float_table,
  71.                        double_table;
  72.     NameLookupTable name_table;
  73.     TypeLookupTable type_table;
  74.  
  75.     //
  76.     //
  77.     //
  78.     NameSymbol *dot_name_symbol,
  79.                *dot_dot_name_symbol,
  80.                *length_name_symbol,
  81.                *init_name_symbol,
  82.                *clinit_name_symbol,
  83.                *block_init_name_symbol,
  84.                *this0_name_symbol,
  85.                *clone_name_symbol,
  86.                *object_name_symbol,
  87.                *type_name_symbol,
  88.                *class_name_symbol,
  89.                *toString_name_symbol,
  90.                *append_name_symbol,
  91.                *forName_name_symbol,
  92.                *getMessage_name_symbol;
  93.  
  94.     //
  95.     //
  96.     //
  97.     TypeSymbol *byte_type,
  98.                *short_type,
  99.                *int_type,
  100.                *long_type,
  101.                *char_type,
  102.                *float_type,
  103.                *double_type,
  104.                *boolean_type,
  105.                *void_type,
  106.                *null_type,
  107.                *no_type;
  108.  
  109.     //
  110.     TypeSymbol *GetType(PackageSymbol *, wchar_t *);
  111.  
  112.     inline TypeSymbol *Serializable()
  113.     {
  114.         if (! Serializable_type)
  115.         {
  116.             PackageSymbol *io_package = ProcessPackage(StringConstant::US_java_SL_io);
  117.             FindPathsToDirectory(io_package);
  118.             Serializable_type = GetType(io_package, StringConstant::US_Serializable);
  119.         }
  120.  
  121.         return Serializable_type;
  122.     }
  123.  
  124.     inline TypeSymbol *Object()
  125.     {
  126.         return (Object_type ? Object_type : Object_type = GetType(system_package, StringConstant::US_Object));
  127.     }
  128.  
  129.     inline TypeSymbol *Cloneable()
  130.     {
  131.         return (Cloneable_type ? Cloneable_type : Cloneable_type = GetType(system_package, StringConstant::US_Cloneable));
  132.     }
  133.  
  134.     inline TypeSymbol *String()
  135.     {
  136.         return (String_type ? String_type : String_type = GetType(system_package, StringConstant::US_String));
  137.     }
  138.  
  139.     inline TypeSymbol *Void()
  140.     {
  141.         return (Void_type ? Void_type : Void_type = GetType(system_package, StringConstant::US_Void));
  142.     }
  143.  
  144.     inline TypeSymbol *Boolean()
  145.     {
  146.         return (Boolean_type ? Boolean_type : Boolean_type = GetType(system_package, StringConstant::US_Boolean));
  147.     }
  148.  
  149.     inline TypeSymbol *Byte()
  150.     {
  151.         return (Byte_type ? Byte_type : Byte_type = GetType(system_package, StringConstant::US_Byte));
  152.     }
  153.  
  154.     inline TypeSymbol *Short()
  155.     {
  156.         return (Short_type ? Short_type : Short_type = GetType(system_package, StringConstant::US_Short));
  157.     }
  158.  
  159.     inline TypeSymbol *Character()
  160.     {
  161.         return (Character_type ? Character_type : Character_type = GetType(system_package, StringConstant::US_Character));
  162.     }
  163.  
  164.     inline TypeSymbol *Integer()
  165.     {
  166.         return (Integer_type ? Integer_type : Integer_type = GetType(system_package, StringConstant::US_Integer));
  167.     }
  168.  
  169.     inline TypeSymbol *Long()
  170.     {
  171.         return (Long_type ? Long_type : Long_type = GetType(system_package, StringConstant::US_Long));
  172.     }
  173.  
  174.     inline TypeSymbol *Float()
  175.     {
  176.         return (Float_type ? Float_type : Float_type = GetType(system_package, StringConstant::US_Float));
  177.     }
  178.  
  179.     inline TypeSymbol *Double()
  180.     {
  181.         return (Double_type ? Double_type : Double_type = GetType(system_package, StringConstant::US_Double));
  182.     }
  183.  
  184.     void InitClassInfo();
  185.     inline TypeSymbol *Class()
  186.     {
  187.         if (! Class_type)
  188.         {
  189.             Class_type = GetType(system_package, StringConstant::US_Class);
  190.             InitClassInfo();
  191.         }
  192.  
  193.         return Class_type;
  194.     }
  195.  
  196.     MethodSymbol *Class_forNameMethod()
  197.     {
  198.         if (! Class_forName_method)
  199.             (void) Class();
  200.         return Class_forName_method;
  201.     }
  202.  
  203.  
  204.     void InitThrowableInfo();
  205.     inline TypeSymbol *Throwable()
  206.     {
  207.         if (! Throwable_type)
  208.         {
  209.             Throwable_type = GetType(system_package, StringConstant::US_Throwable);
  210.             InitThrowableInfo();
  211.         }
  212.  
  213.         return Throwable_type;
  214.     }
  215.  
  216.     MethodSymbol *Throwable_getMessageMethod()
  217.     {
  218.         if (! Throwable_getMessage_method)
  219.             (void) Throwable();
  220.         return Throwable_getMessage_method;
  221.     }
  222.  
  223.     inline TypeSymbol *Exception()
  224.     {
  225.         return (Exception_type
  226.                        ? Exception_type
  227.                        : Exception_type = GetType(system_package, StringConstant::US_Exception));
  228.     }
  229.  
  230.     inline TypeSymbol *RuntimeException()
  231.     {
  232.         return (RuntimeException_type
  233.                        ? RuntimeException_type
  234.                        : RuntimeException_type = GetType(system_package, StringConstant::US_RuntimeException));
  235.     }
  236.  
  237.     inline TypeSymbol *ClassNotFoundException()
  238.     {
  239.         return (ClassNotFoundException_type
  240.                        ? ClassNotFoundException_type
  241.                        : ClassNotFoundException_type = GetType(system_package, StringConstant::US_ClassNotFoundException));
  242.     }
  243.  
  244.     inline TypeSymbol *Error()
  245.     {
  246.         return (Error_type ? Error_type : Error_type = GetType(system_package, StringConstant::US_Error));
  247.     }
  248.  
  249.     inline TypeSymbol *Vector()
  250.     {
  251.         return (Vector_type ? Vector_type : Vector_type = GetType(java_util_package, StringConstant::US_Vector));
  252.     }
  253.  
  254.     void InitNoClassDefFoundErrorInfo();
  255.     inline TypeSymbol *NoClassDefFoundError()
  256.     {
  257.         if (! NoClassDefFoundError_type)
  258.         {
  259.             NoClassDefFoundError_type = GetType(system_package, StringConstant::US_NoClassDefFoundError);
  260.             InitNoClassDefFoundErrorInfo();
  261.         }
  262.  
  263.         return NoClassDefFoundError_type;
  264.     }
  265.  
  266.     MethodSymbol *NoClassDefFoundError_InitMethod()
  267.     {
  268.         if (! NoClassDefFoundError_InitWithString_method)
  269.             (void) NoClassDefFoundError();
  270.         return NoClassDefFoundError_InitWithString_method;
  271.     }
  272.  
  273.  
  274.     void InitStringBufferInfo();
  275.     inline TypeSymbol *StringBuffer()
  276.     {
  277.         if (! StringBuffer_type)
  278.         {
  279.             StringBuffer_type = GetType(system_package, StringConstant::US_StringBuffer);
  280.             InitStringBufferInfo();
  281.         }
  282.  
  283.         return StringBuffer_type;
  284.     }
  285.  
  286.  
  287.     MethodSymbol *StringBuffer_InitMethod()
  288.     {
  289.         if (! StringBuffer_Init_method)
  290.             (void) StringBuffer();
  291.         return StringBuffer_Init_method;
  292.     }
  293.  
  294.  
  295.     MethodSymbol *StringBuffer_InitWithStringMethod()
  296.     {
  297.         if (! StringBuffer_InitWithString_method)
  298.             (void) StringBuffer();
  299.         return StringBuffer_InitWithString_method;
  300.     }
  301.  
  302.  
  303.     MethodSymbol *StringBuffer_toStringMethod()
  304.     {
  305.         if (! StringBuffer_InitWithString_method)
  306.             (void) StringBuffer();
  307.         return StringBuffer_toString_method;
  308.     }
  309.  
  310.  
  311.     MethodSymbol *StringBuffer_append_char_arrayMethod()
  312.     {
  313.         if (! StringBuffer_InitWithString_method)
  314.             (void) StringBuffer();
  315.         return StringBuffer_append_char_array_method;
  316.     }
  317.  
  318.  
  319.     MethodSymbol *StringBuffer_append_charMethod()
  320.     {
  321.         if (! StringBuffer_InitWithString_method)
  322.             (void) StringBuffer();
  323.         return StringBuffer_append_char_method;
  324.     }
  325.  
  326.  
  327.     MethodSymbol *StringBuffer_append_booleanMethod()
  328.     {
  329.         if (! StringBuffer_InitWithString_method)
  330.             (void) StringBuffer();
  331.         return StringBuffer_append_boolean_method;
  332.     }
  333.  
  334.  
  335.     MethodSymbol *StringBuffer_append_intMethod()
  336.     {
  337.         if (! StringBuffer_InitWithString_method)
  338.             (void) StringBuffer();
  339.         return StringBuffer_append_int_method;
  340.     }
  341.  
  342.  
  343.     MethodSymbol *StringBuffer_append_longMethod()
  344.     {
  345.         if (! StringBuffer_InitWithString_method)
  346.             (void) StringBuffer();
  347.         return StringBuffer_append_long_method;
  348.     }
  349.  
  350.  
  351.     MethodSymbol *StringBuffer_append_floatMethod()
  352.     {
  353.         if (! StringBuffer_InitWithString_method)
  354.             (void) StringBuffer();
  355.         return StringBuffer_append_float_method;
  356.     }
  357.  
  358.  
  359.     MethodSymbol *StringBuffer_append_doubleMethod()
  360.     {
  361.         if (! StringBuffer_InitWithString_method)
  362.             (void) StringBuffer();
  363.         return StringBuffer_append_double_method;
  364.     }
  365.  
  366.  
  367.     MethodSymbol *StringBuffer_append_stringMethod()
  368.     {
  369.         if (! StringBuffer_InitWithString_method)
  370.             (void) StringBuffer();
  371.         return StringBuffer_append_string_method;
  372.     }
  373.  
  374.  
  375.     MethodSymbol *StringBuffer_append_objectMethod()
  376.     {
  377.         if (! StringBuffer_InitWithString_method)
  378.             (void) StringBuffer();
  379.         return StringBuffer_append_object_method;
  380.     }
  381.  
  382.     IntLiteralTable    int_pool;
  383.     LongLiteralTable   long_pool;
  384.     FloatLiteralTable  float_pool;
  385.     DoubleLiteralTable double_pool;
  386.     Utf8LiteralTable   Utf8_pool;
  387.  
  388.     Utf8LiteralValue *ConstantValue_literal,
  389.                      *Exceptions_literal,
  390.                      *InnerClasses_literal,
  391.                      *Synthetic_literal,
  392.                      *Deprecated_literal,
  393.                      *LineNumberTable_literal,
  394.                      *LocalVariableTable_literal,
  395.                      *Code_literal,
  396.                      *Sourcefile_literal,
  397.  
  398.                      *null_literal,
  399.                      *this_literal;
  400.  
  401.     Control(ArgumentExpander &, Option &);
  402.     ~Control();
  403.  
  404.     Utf8LiteralValue *ConvertUnicodeToUtf8(wchar_t *source)
  405.     {
  406.         char *target = new char[wcslen(source) * 3 + 1]; // should be big enough for the worst case
  407.         int length = ConvertUnicodeToUtf8(source, target);
  408.         Utf8LiteralValue *literal = Utf8_pool.FindOrInsert(target, length);
  409.         delete [] target;
  410.  
  411.         return literal;
  412.     }
  413.  
  414.     static int ConvertUtf8ToUnicode(wchar_t *, char *, int);
  415.  
  416.     NameSymbol *ConvertUtf8ToUnicode(char *source, int length)
  417.     {
  418.         wchar_t *name = new wchar_t[length + 1];
  419.         int name_length = ConvertUtf8ToUnicode(name, source, length);
  420.         NameSymbol *name_symbol = FindOrInsertName(name, name_length);
  421.         delete [] name;
  422.  
  423.         return name_symbol;
  424.     }
  425.  
  426.     void FindPathsToDirectory(PackageSymbol *);
  427.  
  428.     DirectoryEntry *FindInputFile(FileSymbol *);
  429.     void FindMoreRecentInputFiles(SymbolSet &);
  430.     void RemoveTrashedTypes(SymbolSet &);
  431.     void RereadDirectory(DirectorySymbol *);
  432.     void RereadDirectories();
  433.     void ComputeRecompilationSet(TypeDependenceChecker &);
  434.     bool IncrementalRecompilation();
  435.  
  436.     //
  437.     // The one and only null value constant.
  438.     //
  439.     LiteralValue *NullValue() { return &null_value; }
  440.  
  441.     //
  442.     // The one and only bad value constant.
  443.     //
  444.     LiteralValue *BadValue() { return &bad_value; }
  445.  
  446.     //
  447.     // Note that only names are converted here and not literals, since
  448.     // no error can occur in a name.
  449.     // A literal is converted during the semantic pass so that an
  450.     // accurate diagnostic can be issued in case it is invalid.
  451.     //
  452.     NameSymbol *FindOrInsertName(wchar_t *name, int len)
  453.     {
  454.         NameSymbol *name_symbol = name_table.FindOrInsertName(name, len);
  455.         if (! name_symbol -> Utf8_literal)
  456.             name_symbol -> Utf8_literal = ConvertUnicodeToUtf8(name_symbol -> Name());
  457.  
  458.         return name_symbol;
  459.     }
  460.  
  461.     //
  462.     // Make up a parameter name of the form #(num) and return its name symbol.
  463.     //
  464.     NameSymbol *MakeParameter(int num)
  465.     {
  466.         IntToWstring value(num);
  467.  
  468.         wchar_t str[13];
  469.         str[0] = U_DOLLAR; // '$'
  470.         wcscpy(&str[1], value.String());
  471.  
  472.         return FindOrInsertName(str, value.Length() + 1);
  473.     }
  474.  
  475.     //
  476.     //
  477.     //
  478.     static DirectorySymbol *GetOutputDirectory(FileSymbol *);
  479.     static FileSymbol *GetJavaFile(PackageSymbol *, NameSymbol *);
  480.     static FileSymbol *GetFile(Control &, PackageSymbol *, NameSymbol *);
  481.     static FileSymbol *GetFileFirst(Control &, PackageSymbol *, NameSymbol *);
  482.     static FileSymbol *GetFileBoth(Control &, PackageSymbol *, NameSymbol *);
  483.  
  484.     PackageSymbol *FindOrInsertPackage(LexStream *, AstExpression *);
  485.     void ProcessPackageDeclaration(FileSymbol *, AstPackageDeclaration *);
  486.     void CleanUp(FileSymbol *);
  487.  
  488.     inline bool IsSimpleIntegerValueType(TypeSymbol *type)
  489.     {
  490.         return (type == byte_type || type == short_type || type == int_type || type == char_type);
  491.     }
  492.  
  493.     inline bool IsIntegral(TypeSymbol *type)
  494.     {
  495.         return (IsSimpleIntegerValueType(type) || type == long_type);
  496.     }
  497.  
  498.     inline bool IsFloatingPoint(TypeSymbol *type)
  499.     {
  500.         return (type == float_type || type == double_type);
  501.     }
  502.  
  503.     inline bool IsNumeric(TypeSymbol *type)
  504.     {
  505.         return IsIntegral(type) || IsFloatingPoint(type);
  506.     }
  507.  
  508.     inline bool IsDoubleWordType(TypeSymbol *type)
  509.     {
  510.         return (type == long_type || type == double_type);
  511.     }
  512.  
  513.     inline bool IsPrimitive(TypeSymbol *type)
  514.     {
  515.         return (IsNumeric(type) || type == boolean_type);
  516.     }
  517.  
  518.     inline void ProcessBadType(TypeSymbol *type_symbol)
  519.     {
  520.         type_trash_bin.Next() = type_symbol;
  521.     }
  522.  
  523.     void ProcessHeaders(FileSymbol *);
  524.  
  525. #ifdef TEST
  526.     int input_files_processed,
  527.         class_files_read,
  528.         class_files_written,
  529.         line_count;
  530. #endif
  531.  
  532.     PackageSymbol *ProcessPackage(wchar_t *);
  533.  
  534.     DirectorySymbol *FindSubdirectory(PathSymbol *, wchar_t *, int);
  535.     DirectorySymbol *ProcessSubdirectories(wchar_t *, int);
  536.  
  537. private:
  538.  
  539.     LiteralValue null_value,
  540.                  bad_value;
  541.  
  542.     TypeSymbol *Serializable_type,
  543.  
  544.                *Object_type,
  545.                *Cloneable_type,
  546.                *String_type,
  547.                *Void_type,
  548.                *Boolean_type,
  549.                *Byte_type,
  550.                *Short_type,
  551.                *Character_type,
  552.                *Integer_type,
  553.                *Long_type,
  554.                *Float_type,
  555.                *Double_type,
  556.                *Class_type,
  557.                *Throwable_type,
  558.                *Exception_type,
  559.                *RuntimeException_type,
  560.                *ClassNotFoundException_type,
  561.                *Error_type,
  562.                *Vector_type,
  563.                *NoClassDefFoundError_type,
  564.                *StringBuffer_type;
  565.  
  566.     MethodSymbol *Class_forName_method,
  567.  
  568.                  *Throwable_getMessage_method,
  569.  
  570.                  *NoClassDefFoundError_InitWithString_method,
  571.  
  572.                  *StringBuffer_Init_method,
  573.                  *StringBuffer_InitWithString_method,
  574.                  *StringBuffer_toString_method,
  575.                  *StringBuffer_append_char_array_method,
  576.                  *StringBuffer_append_char_method,
  577.                  *StringBuffer_append_boolean_method,
  578.                  *StringBuffer_append_int_method,
  579.                  *StringBuffer_append_long_method,
  580.                  *StringBuffer_append_float_method,
  581.                  *StringBuffer_append_double_method,
  582.                  *StringBuffer_append_string_method,
  583.                  *StringBuffer_append_object_method;
  584.  
  585.     static int ConvertUnicodeToUtf8(wchar_t *, char *);
  586.  
  587.     void ProcessGlobals();
  588.     void ProcessUnnamedPackage();
  589.     void ProcessPath();
  590.     TypeSymbol *GetPrimitiveType(wchar_t *, char *);
  591.     void ProcessSystemInformation();
  592.  
  593.     void ProcessFile(FileSymbol *);
  594.     void ProcessMembers();
  595.     void ProcessBodies(TypeSymbol *);
  596.  
  597.     void ProcessNewInputFiles(SymbolSet &, ArgumentExpander &, int = 0);
  598.  
  599.     FileSymbol *FindOrInsertJavaInputFile(DirectorySymbol *, NameSymbol *);
  600.     FileSymbol *FindOrInsertJavaInputFile(wchar_t *, int);
  601. };
  602.  
  603. #endif /* control_INCLUDED */
  604.